package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.mall.commons.exception.ExceptionProcessorUtils;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.shopping.converter.ContentConverter;
import com.cskaoyan.shopping.dal.entitys.PanelContent;
import com.cskaoyan.shopping.dal.persistence.PanelContentMapper;
import com.cskaoyan.shopping.dto.NavListResponse;
import com.cskaoyan.shopping.dto.PanelContentDto;
import com.cskaoyan.shopping.service.IContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 蒋镇泽
 * @Description:
 * @Date: 2022-06-18-14:40
 */
@Service
public class IContentServiceImpl implements IContentService {
@Autowired
    PanelContentMapper panelContentMapper;
@Autowired
    ContentConverter contentConverter;
    @Override
    public NavListResponse queryNavList() {
        NavListResponse response = new NavListResponse();
        try {
            List<PanelContent> panelContents=panelContentMapper.selectPanelIdEqual0();
            ArrayList<PanelContentDto> panelContentDtos = new ArrayList<>();
            for (PanelContent panelContent : panelContents) {
                PanelContentDto panelContentDto = contentConverter.panelContent2Dto(panelContent);
                panelContentDtos.add(panelContentDto);
            }
            response.setPannelContentDtos(panelContentDtos);
            response.setCode(ShoppingRetCode.SUCCESS.getCode());
            response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            ExceptionProcessorUtils.wrapperHandlerException(response, e);
        }
        return response;

    }
}
